﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace PortChat
{
    //frame separator
    class FrameSeparator
    {
        //list of frames
        List<String> lstFrames = new List<String>();
        String strDeletedStartEndFlags;
        //separates a frames string into a list of separate frames
        //Startflag| FrameNumber| Quittung|CheckWord | COMName| Code     | EndFlag
        //01111110 | 10000      | 0       |    0     | 0001   | 00000000 | 0111111001111110 | 10000      | 0       |    0     | 0001   | 00000000 | 01111110
        public List<String> separateFrames(String strFrames)
        {
            //everything between startflag and endflag is a frame
            Regex rxGetFrame = new Regex("01111110.*?01111110");
            MatchCollection matches = rxGetFrame.Matches(strFrames);
            foreach (Match match in matches)
            {
                strDeletedStartEndFlags = match.ToString();
                strDeletedStartEndFlags = strDeletedStartEndFlags.Replace("01111110", "");
                lstFrames.Add(strDeletedStartEndFlags);
            }
            return lstFrames;
        }
    }
}
